using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Microsoft.PowerShell.CmdletManagement
{
    [System.Windows.Markup.ContentProperty("Label")]
    public partial class ExtendedPasswordBox : System.Windows.Controls.UserControl
    {
        public ExtendedPasswordBox()
        {
            InitializeComponent();

            UserInput.Background = SystemColors.ControlBrush;
            //UserInput.IsReadOnly = true;
        }

        public string Label
        {
            get { return (string) GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }

        public string Value
        {
            get
            {
                //return (string) GetValue(PasswordBoxAssistant.BoundPassword);
                return UserInput.Password;
            }
            set
            {
                //SetValue(PasswordBoxAssistant.BoundPassword, value);
                UserInput.Password = value;
            }
        }

        public string HelpText
        {
            get { return (string) GetValue(HelpTextProperty); }
            set { SetValue(HelpTextProperty, value); }
        }

        public string WarningValue
        {
            get { return warningValue; }
            set { warningValue = value; }
        }
        
        private string warningValue = "dba32e8c-6cb7-442b-abf3-3a24b08a71cc";

        //private void ValueChanged(object sender, RoutedEventArgs e)
        //{
        //    if (Value != warningValue)
        //    {
        //        Binding binding = BindingOperations.GetBinding(UserInput, PasswordBoxAssistant.BoundPassword);

        //        if (binding != null)
        //        {
        //            binding.ValidationRules.Clear();
        //        }
        //    }
        //    else
        //    {
        //        Binding binding = BindingOperations.GetBinding(UserInput, PasswordBoxAssistant.BoundPassword);

        //        if (binding != null)
        //        {
        //            binding.ValidationRules.Clear();
        //            binding.ValidationRules.Add(new TriStateValidationRule());
        //        }
        //    }
        //}

        public static readonly DependencyProperty LabelProperty =
            DependencyProperty.Register("Label", typeof(string), typeof(ExtendedPasswordBox));
        public static readonly DependencyProperty PasswordProperty =
            DependencyProperty.Register("Value", typeof(string), typeof(ExtendedPasswordBox));
        public static readonly DependencyProperty HelpTextProperty =
            DependencyProperty.Register("HelpText", typeof(string), typeof(ExtendedPasswordBox));
     }
}